package com.wwj.utils;

/**
 * Created by tsi on 2016/11/23.
 */
public class PayCodeUtil {

    /**
     * 生成消费码 (yyyy yyyy yy)
     *
     * @return
     */
    public static String getPayCode() {
        StringBuffer payCodeBuffer = new StringBuffer();

        // 生成一位随机数
        while (true) {
            int r = (int) (10 * (Math.random()));
            if (r > 0) {
                payCodeBuffer.append(r);
                break;
            }
        }

        // 生成3位随机数
        for (int i = 0; i < 3; i++) {
            int r = (int) (10 * (Math.random()));
            payCodeBuffer.append(r);
        }

        // 加空格
        //payCodeBuffer.append(" ");

        // 生成4位随机数
        for (int i = 0; i < 4; i++) {
            int r = (int) (10 * (Math.random()));
            payCodeBuffer.append(r);
        }

        // 加空格
        //payCodeBuffer.append(" ");

        // 生成2位随机数
        for (int i = 0; i < 2; i++) {
            int r = (int) (10 * (Math.random()));
            payCodeBuffer.append(r);
        }

        return payCodeBuffer.toString();
    }
}
